// pages/profileList/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    originList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow(options) {
    try {
      const healthInfo = wx.getStorageSync('healthInfo')
      const keys = Object.keys(healthInfo);
      console.log('healthInfo', healthInfo)
      const list = [];
      for (const key in healthInfo) {
        console.log('-----name', keys)
        const obj = {
          name: key,
          count: healthInfo[key]?.length,
          age: healthInfo[key]?.[0]?.age,
        }
        if (healthInfo[key]?.length && key) {
          list.push(obj)
        }
      }
      console.log('---list', list)
      this.setData({
        list,
        originList: JSON.parse(JSON.stringify(list)),
      })
    } catch (e) {
      // Do something when catch error
      console.log('0000e', e)
    }
  },

  hanldleBlur (e) {
    const { value } = e.detail;
    const originList = this.data.originList;
    const list = [];
    originList.forEach((item) => {
      if (item.name.includes(value)) {
        list.push(item)
      }
    })
    this.setData({
      list
    })
  },

  handleClick (e) {
    const { names } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/profileInfo/index?name=${names}`,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})